﻿//Easy = (Easy == null ? new Object() : Easy);
Easy = {
    //定义内置字段
    __EntityName: "",
    __ViewName: "",
    __Content: {},
    __Data: [],
    __Field: {},
    //初始化方法
    Init: function () {
        //抛出开始初始化事件
        $(document).trigger(Easy.Event.BeginInit);

        //获取EntityName、ViewName
        Easy.__EntityName = $.getQueryString("en");
        Easy.__ViewName = $.getQueryString("vn");
        //初始化监听器
        Easy.setControl();

        //抛出结束初始化事件
        $(document).trigger(Easy.Event.EndInit, Easy.__EntityName, Easy.__ViewName, null, null, null, null);
    },
    //初始化监听控制器
    setControl: function () {
        //监听获取数据事件
        $(document).on(Easy.Event.EndInit, Easy.Function.GetMobileInitData);
        //监听加载完成事件
        $(document).on(Easy.Event.EndGetData, Easy.Function.bindTemplete);
        //监听绑定模板完成事件
        $(document).on(Easy.Event.EndBindTemplete, Easy.Function.bindData);
    },
    //事件仓库
    Event: {
        BeginInit: "_BeginInit",
        EndInit: "_EndInit",
        BeginGetData: "_BeginGetData",
        EndGetData: "_EndGetData",
        BeginBindTemplete: "_BeginBindTemplete",
        EndBindTemplete: "_EndBindTemplete",
    },
    //处理函数仓库
    Function: {
        getField: function () {
            $.ajax({
                type: "post",
                url: "/Service/Data/GetEntityField.ashx",
                dataType: "json",
                async: false,
                data: {
                    entityname: Easy.__EntityName, viewname: Easy.__ViewName
                },
                success: function (data, textStatus) {
                    Easy.__Field = data;
                },
                error: function (data) {
                    debugger;
                }
            });
        },
        GetMobileInitData: function (e, entityname, viewname, filterData, order, pagenum, pagesize) {
            $(document).trigger(Easy.Event.BeginGetData);
            $.ajax({
                type: "post",
                url: "/Service/Data/GetMobileInitData.ashx",
                dataType: "json",
                data: {
                    entityname: entityname,
                    order: order,
                    pagenum: (pagenum == null ? 0 : pagenum),
                    pagesize: (pagesize == null ? 20 : pagesize),
                    filter: (filterData == null ? "{'Conditions':[],'FilterOperator':'AND','Filters':[]}" : filterData),
                    ViewName: viewname
                },
                success: function (data, textStatus) {
                    Easy.__Content = data;
                    debugger;
                    //$(data.List).each(function () {
                    //    Easy.__Data.push(this);
                    //})

                    $(document).trigger(Easy.Event.EndGetData);
                },
                error: function (data) {
                    debugger;
                }
            });
        },
        bindTemplete: function (e) {
            //抛出开始绑定模板事件
            $(document).trigger(Easy.Event.BeginBindTemplete);
            $("#ViewContent").html(Easy.__Content.Templete);
            //抛出结束绑定模板事件
            setTimeout("$(document).trigger(Easy.Event.EndBindTemplete)",1000);
        },
        bindData: function (e) {
            //绑定VUE模型
            var ViewApp = new Vue({
                el: '#ViewContent',
                data: {
                    List: Easy.__Data
                }
            })
            //为模型初始化数据
            $(Easy.__Content.Data).each(function () {
                Easy.__Data.push(this);
            })
        }
    }
}












